package com.yitongmao.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yitongmao.bean.SearchNews;
import com.yitongmao.yitmfruit.R;

import java.util.List;

/*
* 作者：梁伟航 on 2017/7/14 17:05
* 类的用途：
*/
public class HistorySearchGridViewAdapter extends BaseAdapter{
    private Context context;
    private List<SearchNews> mSearchNewsList;
    public HistorySearchGridViewAdapter(Context context, List<SearchNews> mSearchNewsList) {
        this.context=context;
        this.mSearchNewsList=mSearchNewsList;
    }

    @Override
    public int getCount() {
        return mSearchNewsList.size();
    }

    @Override
    public Object getItem(int i) {
        return mSearchNewsList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(context, R.layout.historysearchgridviewitem, null);
            viewHolder.mHistorySearchGridTextView =  (TextView) view.findViewById(R.id.mHistorySearchGridTextView);
            view.setTag(viewHolder);//绑定ViewHolder对象
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.mHistorySearchGridTextView.setText(mSearchNewsList.get(i).getmSearchBody());
        return view;
    }
    class ViewHolder {
        public TextView mHistorySearchGridTextView;
    }

}
